package com.sportswork.sportswork.controller.admin;

import com.sportswork.sportswork.core.entity.Classroom;
import com.sportswork.sportswork.core.entity.Info;
import com.sportswork.sportswork.core.service.dto.PageDTO;
import com.sportswork.sportswork.core.service.impl.InfoServiceImp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author dengwei
 * @date 2020/2/3 12:11
 * @description
 */
@Slf4j
@Controller("InfoController")
public class InfoController {
    @Resource
    private InfoServiceImp infoServiceImp;

    @RequestMapping("/admin/Info/list")
    public String List(){
        return "/pages/view/admin/Info/list";
    }

    @RequestMapping("/admin/Info/getAllInfo")
    @ResponseBody
    public Object getAllInfo(String title){
        return new  PageDTO<Info>().toPageDTO(infoServiceImp.getAllInfos(title));
    }

    @RequestMapping(value = "/admin/Info/add", method = RequestMethod.POST)
    @ResponseBody
    public String add(Info info) {
        infoServiceImp.addInfo(info);
        return "success";
    }

    @RequestMapping(value = "/admin/Info/edit", method = RequestMethod.POST)
    @ResponseBody
    public String edit(Info info) {
        infoServiceImp.setInfo(info);
        return "success";
    }

    @RequestMapping(value = "/admin/Info/delete", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestParam String id) {
        infoServiceImp.deleteInfo(id);
        return "true";
    }

    @RequestMapping(value = "/admin/Info/deletes", method = RequestMethod.POST)
    @ResponseBody
    public String deletes(@RequestParam String ids) {
        infoServiceImp.deleteInfos(ids );
        return "true";
    }
}
